// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.11/esri/copyright.txt for details.
//>>built
define("require exports ../../core/tsSupport/declareExtendsHelper ../../core/tsSupport/decorateHelper ../../core/Handles ../../core/Logger ../../core/unitUtils ../../core/watchUtils ../../core/accessorSupport/decorators ../../views/3d/interactive/measurementTools/directLineMeasurement3D/ShowLaserHeightTool ../support/InteractiveToolViewModel".split(" "),
function(r, t, h, d, k, l, m, n, c, p, q) {
    var e = "metric imperial inches feet yards miles nautical-miles us-feet meters kilometers".split(" "),
    f = l.getLogger("esri.widgets.DirectLineMeasurement3D.ShowLaserHeightViewModel");
    return function(g) {
        function a(b) {
            b = g.call(this, b) || this;
            b.supportedViewType = "3d";
            b._handles = new k;
            b._userUnitOptions = null;
            b._userUnit = null;
            return b
        }
        h(a, g);
        a.prototype.initialize = function() {
            var b = this;
            this._handles.add([n.init(this, "unit",
            function(a) {
                b.tool && (b.tool.unit = a)
            })])
        };
        a.prototype.destroy = function() {
            this._handles.destroy();
            this._handles = null
        };
        Object.defineProperty(a.prototype, "state", {
            get: function() {
                return this.isDisabled ? "disabled": this.tool.state
            },
            enumerable: !0,
            configurable: !0
        });
        Object.defineProperty(a.prototype, "measurement", {
            get: function() {
                if (!this.tool) return null;
                var b = this.tool.model,
                a = b.measurementMode,
                c = "geodesic" === a,
                b = b.validMeasurement;
                return {
                    mode: a,
                    directDistance: {
                        text: c ? null: this.tool.triangleView.directLabel,
                        state: b && !c ? "available": "unavailable"
                    },
                    horizontalDistance: {
                        text: this.tool.triangleView.horizontalLabel,
                        state: b ? "available": "unavailable"
                    },
                    verticalDistance: {
                        text: this.tool.triangleView.verticalLabel,
                        state: b ? "available": "unavailable"
                    }
                }
            },
            enumerable: !0,
            configurable: !0
        });
        Object.defineProperty(a.prototype, "defaultUnit", {
            get: function() {
                return this.defaultUnitFromPortal || this.defaultUnitFromSpatialReference || "metric"
            },
            enumerable: !0,
            configurable: !0
        });
        Object.defineProperty(a.prototype, "defaultUnitFromSpatialReference", {
            get: function() {
                return m.getDefaultUnitSystem(this.view && this.view.spatialReference)
            },
            enumerable: !0,
            configurable: !0
        });
        Object.defineProperty(a.prototype, "defaultUnitFromPortal", {
            get: function() {
                var b = this.get("view.map.portalItem.portal");
                if (!b) return null;
                switch (b.user && b.user.units || b.units) {
                case "metric":
                    return "metric";
                case "english":
                    return "imperial";
                default:
                    return null
                }
            },
            enumerable: !0,
            configurable: !0
        });
        Object.defineProperty(a.prototype, "unitOptions", {
            get: function() {
                return this._filteredOrAllUnits(this._userUnitOptions)
            },
            set: function(b) {
                this._userUnitOptions = b;
                this._set("unitOptions", this._filteredOrAllUnits(this._userUnitOptions))
            },
            enumerable: !0,
            configurable: !0
        });
        Object.defineProperty(a.prototype, "unit", {
            get: function() {
                return this._userUnit ? this._userUnit = this._findSelectableUnit(this._userUnit, this.defaultUnit) : this._findSelectableUnit(this.defaultUnit)
            },
            set: function(b) {
                this._userUnit = b ? this._findSelectableUnit(b, this._userUnit) : null;
                this.notifyChange("unit")
            },
            enumerable: !0,
            configurable: !0
        });
        a.prototype.newMeasurement = function() {
            this.tool && this.tool.newMeasurement()
        };
        a.prototype.clearMeasurement = function() {
            this.tool && this.tool.clearMeasurement()
        };
        a.prototype.createToolParams = function() {
            return {
                toolConstructor: p,
                constructorArguments: {
                    unit: this.unit
                }
            }
        };
        a.prototype.logUnsupportedError = function() {
            f.error("DirectLineMeasurement3D widget is not implemented for MapView")
        };
        a.prototype.logError = function() {
            for (var b = [], a = 0; a < arguments.length; a++) b[a] = arguments[a];
            f.error.apply(f, b)
        };
        a.prototype._findSelectableUnit = function(b, a) {
            var c = this.unitOptions;
            return - 1 !== c.indexOf(b) ? b: a ? this._findSelectableUnit(a) : c[0]
        };
        a.prototype._filteredOrAllUnits = function(a) {
            if (!a) return e.slice();
            a = a.filter(function(a) {
                return - 1 !== e.indexOf(a)
            });
            return 0 === a.length ? e.slice() : a
        };
        d([c.property({
            dependsOn: ["view.ready", "isDisabled", "tool.state"],
            readOnly: !0
        })], a.prototype, "state", null);
        d([c.property({
            dependsOn: "view.ready tool.triangleView tool.model.directDistance tool.model.horizontalDistance tool.model.verticalDistance tool.model.geodesicDistance tool.model.measurementMode".split(" "),
            readOnly: !0
        })], a.prototype, "measurement", null);
        d([c.property()], a.prototype, "tool", void 0);
        d([c.property({
            readOnly: !0,
            dependsOn: ["defaultUnitFromPortal", "defaultUnitFromSpatialReference"]
        })], a.prototype, "defaultUnit", null);
        d([c.property({
            readOnly: !0,
            dependsOn: ["view.spatialReference"]
        })], a.prototype, "defaultUnitFromSpatialReference", null);
        d([c.property({
            readOnly: !0,
            dependsOn: ["view.map.portalItem.portal.units", "view.map.portalItem.portal.user.units"]
        })], a.prototype, "defaultUnitFromPortal", null);
        d([c.property({
            dependsOn: ["view.spatialReference"]
        })], a.prototype, "unitOptions", null);
        d([c.property({
            dependsOn: ["unitOptions", "defaultUnit"]
        })], a.prototype, "unit", null);
        return a = d([c.subclass("esri.widgets.DirectLineMeasurement3D.ShowLaserHeightViewModel")], a)
    } (c.declared(q))
});